package com.ruoyi.web.controller.jxgy;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.jxgy.domain.JxgyStudent;
import com.ruoyi.jxgy.service.IJxgyStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学生信息Controller
 * 
 * @author hujiale
 * @date 2023-04-26
 */
@RestController
@RequestMapping("/jxgy/student")
public class JxgyStudentController extends BaseController
{
    @Autowired
    private IJxgyStudentService jxgyStudentService;

    /**
     * 查询学生信息列表
     */
    @PreAuthorize("@ss.hasPermi('jxgy:student:list')")
    @GetMapping("/list")
    public TableDataInfo list(JxgyStudent jxgyStudent)
    {
        startPage();
        List<JxgyStudent> list = jxgyStudentService.selectJxgyStudentList(jxgyStudent);
        return getDataTable(list);
    }

    /**
     * 导出学生信息列表
     */
    @PreAuthorize("@ss.hasPermi('jxgy:student:export')")
    @Log(title = "学生信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JxgyStudent jxgyStudent)
    {
        List<JxgyStudent> list = jxgyStudentService.selectJxgyStudentList(jxgyStudent);
        ExcelUtil<JxgyStudent> util = new ExcelUtil<JxgyStudent>(JxgyStudent.class);
        util.exportExcel(response, list, "学生信息数据");
    }

    /**
     * 获取学生信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('jxgy:student:query')")
    @GetMapping(value = "/{stuId}")
    public AjaxResult getInfo(@PathVariable("stuId") Long stuId)
    {
        return AjaxResult.success(jxgyStudentService.selectJxgyStudentByStuId(stuId));
    }

    /**
     * 新增学生信息
     */
    @PreAuthorize("@ss.hasPermi('jxgy:student:add')")
    @Log(title = "学生信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JxgyStudent jxgyStudent)
    {
        return toAjax(jxgyStudentService.insertJxgyStudent(jxgyStudent));
    }

    /**
     * 修改学生信息
     */
    @PreAuthorize("@ss.hasPermi('jxgy:student:edit')")
    @Log(title = "学生信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JxgyStudent jxgyStudent)
    {
        return toAjax(jxgyStudentService.updateJxgyStudent(jxgyStudent));
    }

    /**
     * 删除学生信息
     */
    @PreAuthorize("@ss.hasPermi('jxgy:student:remove')")
    @Log(title = "学生信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stuIds}")
    public AjaxResult remove(@PathVariable Long[] stuIds)
    {
        return toAjax(jxgyStudentService.deleteJxgyStudentByStuIds(stuIds));
    }
}
